package com.jcw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jcw.common.R;
import com.jcw.domain.Category;
import com.jcw.service.CategoryService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("/page")
    public R<Page> pageR(@RequestParam int page,int pageSize){
        return categoryService.pagination(page,pageSize);
    }

    @PostMapping
    public R<String> addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    @PutMapping
    public R<String> editCategory(@RequestBody Category category){
        return categoryService.editCategory(category);
    }

    @DeleteMapping
    public R<String> removeCategory(@RequestParam Long ids){
        return categoryService.removeCategory(ids);
    }

    @GetMapping("/list")
    public R<List> categoryList(Integer type){
        return categoryService.getCategoryList(type);
    }
}
